package com.sgcc.ln.pmos.e_ln_home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.sgcc.pmos.nativesdk.R;
import com.sgcc.ln.pmos.common.base.BaseRecyclerAdapter;
import com.sgcc.ln.pmos.common.bean.ChartDataBean;

import me.jessyan.autosize.utils.AutoSizeUtils;

/**
 * 文件名：CurveEditorAdapter
 * 作者：Turbo
 * 时间： 12/29/20 10:35 AM
 * 蚁穴虽小，溃之千里。
 */
public class CurveEditorlineRVAdapter extends BaseRecyclerAdapter<ChartDataBean> {

    private Context mContext;
    private int mStepSpace;
    private int max;


    public CurveEditorlineRVAdapter(Context context, int stepSpace, int maxparam) {
        mContext = context;
        mStepSpace = stepSpace;
        max = maxparam;
    }

    @Override
    public RecyclerView.ViewHolder onCreate(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.horizontal_line_item, parent, false);
        return new CurveEditorRVHolder(view);
    }

    @Override
    public void onBind(RecyclerView.ViewHolder viewHolder, int position, ChartDataBean data) {
        CurveEditorRVHolder holder = (CurveEditorRVHolder) viewHolder;
        holder.mLine.setVisibility(position == 0 ? View.GONE : View.VISIBLE);

        RecyclerView.LayoutParams linearParams = (RecyclerView.LayoutParams) holder.mRlParent.getLayoutParams();
        if (position == 0) {
            linearParams.setMargins(-(mStepSpace / 2) + AutoSizeUtils.dp2px(mContext, 100), 0, 0, 0);
        }  else {
            linearParams.setMargins(0, 0, 0, 0);
        }
        linearParams.width = mStepSpace;
        holder.mRlParent.setLayoutParams(linearParams);
        int each = max / 5;
        holder.mTv5.setText(each * 5 + "");
        holder.mTv4.setText(each * 4 + "");
        holder.mTv3.setText(each * 3 + "");
        holder.mTv2.setText(each * 2 + "");
        holder.mTv1.setText(each + "");
        if (position == 0) {
            holder.mRlLeft.setVisibility(View.VISIBLE);
            holder.mLine.setVisibility(View.GONE);
        } else {
            holder.mRlLeft.setVisibility(View.GONE);
            holder.mLine.setVisibility(View.VISIBLE);
        }
    }

    class CurveEditorRVHolder extends RecyclerView.ViewHolder {
        private RelativeLayout mRlParent;
        private View mLine;
        private RelativeLayout mRlLeft;
        private TextView mTvLine;
        private LinearLayout mLlY;
        private TextView mTv5;
        private TextView mTv4;
        private TextView mTv3;
        private TextView mTv2;
        private TextView mTv1;

        public CurveEditorRVHolder(View itemView) {
            super(itemView);
            mRlParent = (RelativeLayout) itemView.findViewById(R.id.rl_parent);
            mLine = (View) itemView.findViewById(R.id.line);
            mRlParent = (RelativeLayout) itemView.findViewById(R.id.rl_parent);
            mRlLeft = (RelativeLayout) itemView.findViewById(R.id.rl_left);
            mTvLine = (TextView) itemView.findViewById(R.id.tv_line);
            mLlY = (LinearLayout) itemView.findViewById(R.id.ll_y);
            mTv5 = (TextView) itemView.findViewById(R.id.tv_5);
            mTv4 = (TextView) itemView.findViewById(R.id.tv_4);
            mTv3 = (TextView) itemView.findViewById(R.id.tv_3);
            mTv2 = (TextView) itemView.findViewById(R.id.tv_2);
            mTv1 = (TextView) itemView.findViewById(R.id.tv_1);
        }
    }
}
